# Exemplo de script para obter a cotação do dólar
library(httr)
library(jsonlite)
install.packages("plotly")
## Warning: o pacote 'plotly' está em uso e não será instalado
library(plotly)
# Usar uma API de cotação do dólar
url <- "https://economia.awesomeapi.com.br/json/last/USD-BRL"
response <- GET(url)
dolar_data <- fromJSON(content(response, "text"))
# Mostrar o valor do dólar
dolar_value <- dolar_data$USDBRL$bid
cat("Cotação atual do Dólar: R$", dolar_value)
## Cotação atual do Dólar: R$ 5.5942
# Previsão do tempo usando uma API de tempo
weather_url <- "https://api.open-meteo.com/v1/forecast?latitude=-32.03&longitude=-52.09¤t_weather=true"
weather_response <- GET(weather_url)
weather_data <- fromJSON(content(weather_response, "text"))
cat("Temperatura atual em Rio Grande: ", weather_data$current_weather$temperature, "°C")
## Temperatura atual em Rio Grande: 17.6 °C
# Criando um gráfico de exemplo para o dólar
data <- data.frame(dias = 1:7, valor_dolar = c(5.20, 5.25, 5.30, 5.35, 5.50, 5.45, 5.55))
fig <- plot_ly(data, x = ~dias, y = ~valor_dolar, type = 'scatter', mode = 'lines+markers')
fig <- fig %>% layout(title = "Cotação do Dólar nos Últimos 7 Dias",
xaxis = list(title = "Dias"),
yaxis = list(title = "Valor (R$)"))
fig